/// Created by Nazariy Jaworski Copyright (c) 2013
/// Bot program
///
/// botui.h -
///  implements user interface (console for now) for
///  controlling application behavior
///
/// To Do list:
///  - ...
///
/// v 0.1        03.04.2013

#ifndef BOTUI_H
#define BOTUI_H

#include <iostream>
#include <QThread>
#include <QString>

//TO DO -   move these things into some external
//          file to allow user modify them
#define UI_STR_TITLE_LINE               "Bot->"
#define UI_STR_MESSAGE_INFO             " ---Bot console user interface v 0.1---\n"
#define UI_STR_MESSAGE_HELP             "TO DO\n"

#define UI_STR_COMMAND_EXIT             "exit"
#define UI_STR_COMMAND_INFO             "info"
#define UI_STR_COMMAND_REGISTER         "register"
#define UI_STR_COMMAND_CLIENTS          "clients"
#define UI_STR_COMMAND_OCLPLATFORMS     "OCLPlatforms"
#define UI_STR_COMMAND_OCLDEVICES       "OCLDevices"
#define UI_STR_COMMAND_RUNWEBSERVER     "runwebserver"
#define UI_STR_COMMAND_STOPWEBSERVER    "stopwebserver"

#include "botwtui.h"

class BotUI : public QThread //, public BotUICommands
{
    Q_OBJECT

    public: WebServerRunner *_myWServerRunner = nullptr;

    public: bool    isOk;
    ///< If is not Ok - shutdown application :), default - true

    public: QString lastCommand;

    public: QString _hiddenLogText;

    private: BotUI(); ///< Common constructor

    /// \todo make it non-singleton
    public: static BotUI& GetInstance()
    {
        static BotUI _singleInstanceOfBotUI;
        return _singleInstanceOfBotUI;
    }

    public: virtual void run();

    Q_SIGNAL void SIGNAL_RegisterAtEnvironment() const;
    ///< UI Command - use to register Bot at environment

    Q_SIGNAL void SIGNAL_ShowClients() const;
    ///< UI Command - use to show connected clients

    Q_SIGNAL void SIGNAL_Exit() const;
    ///< UI Command - use to exit application

    Q_SIGNAL void SIGNAL_ShowOCLPlatforms() const;
    ///< UI Command - use to show OpenCL platforms

    Q_SIGNAL void SIGNAL_ShowOCLDevices() const;
    ///< UI Command - use to show OpenCL platforms

    Q_SIGNAL void SIGNAL_RunWebSerwer() const;
    ///< UI Command - use to run WT Web UI for Bot Server (not for Web Client)

    Q_SIGNAL void SIGNAL_StopWebSerwer() const;
    ///< UI Command - use to stop WT Web UI for Bot Server

    Q_SIGNAL void SIGNAL_FatalError(QString message) const;
    ///< UI Output, connect to Bot SLOT_FatalError, use to throw exeption and exit application

    Q_SIGNAL void SIGNAL_WriteToLog(const QString message)  const;
    ///< Signal for writing data to log file (do not use for now, Logger automatically does it)

    //Q_SIGNAL void SIGNAL_WriteWebUIString(QString message) const;
    ///< Web UI redirection, if exist web Ui

    Q_SLOT void SLOT_WriteUIString(QString message) //override
    {
        std::cout << message.toStdString() << UI_STR_TITLE_LINE;
        //Q_EMIT SIGNAL_WriteWebUIString( message );
        _hiddenLogText += message;
        BotWtUI::updateAllUserSessions();
    }

    Q_SLOT void SLOT_WriteUIStringFromWeb(QString message) //override
    {
        std::cout << message.toStdString() << UI_STR_TITLE_LINE;
    }


    ~BotUI(); ///< Common destructor
};

#endif // BOTUI_H
